package lj.netty.bean;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lj.a.protocol.lj.bean.LJProtocolInfo;
import lombok.Data;

/**
 * @author: liuwenju
 * @date: 2023/6/20 11:43
 * @version: 1.0
 */
@Data
public class LJNettyMsgContext {

    private LJNettyBo LJNettyBo;

    private LJProtocolInfo ljProtocolInfo;

    public byte[] getData() {
        return ObjectUtil.defaultIfNull(ljProtocolInfo.getData(), new byte[]{});
    }

    public String getDataStr() {
        return new String(getData());
    }

    public <T> T getData(Class<T> tClass) {
        String str = new String(getData());
        return JSONUtil.toBean(StrUtil.blankToDefault(str, "{}"), tClass);
    }

}
